//
//  IconCollectionViewCell.m
//  FNer
//
//  Created by 王展 on 15/10/6.
//  Copyright (c) 2015年 wangzhan. All rights reserved.
//

#import "IconCollectionViewCell.h"
#import "ImageCollectionViewCell.h"
#import "DetailHtworld.h"

@implementation IconCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createIconCell];
    }
    return self;
}

-(void)createIconCell
{
    //头像
    self.headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10 * XWIDTH, 10 * XHIGHT, 45 * XWIDTH, 45 * XWIDTH)];
    self.headImageView.layer.masksToBounds = YES;
    self.headImageView.layer.cornerRadius = 45 * XWIDTH / 2;
    self.headImageView.backgroundColor = [UIColor colorWithRed:240 / 255.0 green:240 / 255.0 blue:240 / 255.0 alpha:1];
    [self.contentView addSubview:self.headImageView];
    //用户名
    self.userName = [[UILabel alloc] initWithFrame:CGRectMake(65 * XWIDTH, 10 * XHIGHT, 200 * XWIDTH, 20 * XHIGHT)];
//    self.userName.backgroundColor = [UIColor lightGrayColor];
    self.userName.textColor = [UIColor colorWithRed:43 / 255.0 green:130 /255.0 blue:199 / 255.0 alpha:1];
    self.userName.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.userName];
    //用户发表
    self.userSay = [[UILabel alloc] initWithFrame:CGRectMake(65 * XWIDTH, 35 * XHIGHT, 270 * XWIDTH, 20 * XHIGHT)];
//    self.userSay.backgroundColor = [UIColor lightGrayColor];
    self.userSay.textColor = [UIColor grayColor];
    self.userSay.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.userSay];
    
    
    //三张图
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(self.contentView.frame.size.height- 65 * XHIGHT - 20 * XHIGHT, self.contentView.frame.size.height- 65 * XHIGHT - 20 * XHIGHT);
    flowLayout.minimumLineSpacing = 5 * XWIDTH;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.sectionInset = UIEdgeInsetsMake(10 * XHIGHT, 0, 10 * XHIGHT, 0);
    
    self.detailCV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 65 * XHIGHT, self.contentView.frame.size.width, self.contentView.frame.size.height - 65 * XHIGHT) collectionViewLayout:flowLayout];
    self.detailCV.delegate = self;
    self.detailCV.dataSource = self;
    [self.detailCV registerClass:[ImageCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    self.detailCV.backgroundColor = [UIColor whiteColor];
    
    [self.contentView addSubview:self.detailCV];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.ImageArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    ImageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor lightGrayColor];
    
    cell.aHtworld = [self.ImageArray objectAtIndex:indexPath.row];
    
    return cell;
}

//点击imageViewCell触发的方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%ld",indexPath.row);
    [self.myAgent pushIconDetail:self.auser indexPath:indexPath.row];
}


-(void)setAuser:(User *)auser
{
    _auser = auser;
    self.userName.text = self.auser.userName;
    self.userSay.text = self.auser.platformSign;
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:self.auser.userAvatar]];
    
    self.ImageArray = [NSMutableArray array];
    for (NSMutableDictionary *dic in self.auser.htworld) {
        DetailHtworld *ahtWorld = [[DetailHtworld alloc] init];
        [ahtWorld setValuesForKeysWithDictionary:dic];
        [self.ImageArray addObject:ahtWorld];
    }

    [self.detailCV reloadData];
}


@end
